package np13.sddb.queries;

import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import np13.Slime;
import np13.Smell;
import np13.sddb.Result;

/**
 * Represents a get {@link Query}. A get query is used to retrieve a record from
 * the database. After this query has been processed, the {@link Result} will be
 * shown on the display.
 */
public class GetRecordQuery implements Query {

	/**
	 * The slime of interest.
	 */
	private final Slime slime;

	/**
	 * Creates a get query.
	 * 
	 * @param slime
	 *            The slime of interest.
	 */
	public GetRecordQuery(Slime slime) {
		this.slime = slime;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see np13.sddb.queries.Query#applyToDB(java.util.Map)
	 */
	/**
	 * Evtl. Ohne synchronized wegen referenz auf Variablen
	 * 
	 */
	@Override
	public synchronized Result applyToDB(Map<Slime, List<Smell>> db) {
		if (db.get(slime) == null) {
			db.put(slime, new LinkedList<Smell>());
		}
		return new Result(slime, db.get(slime));
	}

}
